For LScript's C-like syntax, the following keywords and operators are used:
if else while pragma var break switch case library const continue return True/true False/false Nil/nil = + - * / == != <= >= += -= *= /= ++ -- || && ! % & ^ << >> |= ^= &=LScript also allows you to use AREXX-like keywords in constructing your scripts:
begin end then do to select when byExamples of this alternate syntax can be found in the LScript example script file2.ls.
Consider the following example:
In the case of while, the condition upon which the control
loop is based is once again evaluated, and program execution
continues from there.
In the case of a for loop, the post-loop code is evaluated,
and the condition upon which the control loop is based is re-
evaluated. Program execution continues from that point.
Comments In LScript
You can embed comments into your LScripts using standard
C/C++ syntax. Single lines can be commented with the C++-
standard double-slash:
jitter(1.5); // make it uniformly ugly
Alternatively, multiple lines can be commented using the C-
standard '/*' '*/' token pair:
/*
multiple
lines
of
comments
*/
Control Structures
Control structures in LScript provide the script programmer the
facilities to design structured programs. These control
structures are documented in the following sections.if/else
The if operator allows the LScript to make decisions about
what should be executed. This operator supports two different
styles of syntax. The first is identical to C:
if((f.eof() == false) && (size(tokens) > 1) &&
(tokens[1] == "Plugin"))
info(tokens[1]," ",tokens[2]);
The second style is similar to AREXX:
if f.eof() == false and
size(tokens) > 1 and
tokens[1] == "Plugin" then
info(tokens[1]," ",tokens[2]));
If operators that host more than one executable statement must
house those statements inside a block control, identical in
structure to that used by user-defined procedures.
if(file == nil)
{
error("Cannot create scene file ",sceneFile);
return;
}
or, alternately,
if file == nil then
begin
error("Cannot create scene file ",sceneFile);
return;
end
If operators can facilitate "either/or" situations through the
use of an else clause. The else clause follows the executable
statement (or block control) for the if operator:
if(lensFlare[index])
{
file.writeln("LensFlare 1");
...
}
else
file.writeln("LensFlare 0");
while
The while operator provides looping capabilities within LScript.
It will execute a statement, or sequence of statements if they
are inclosed within a block control, as long as a condition
evaluates to a boolean true value. This control takes the
form:
while ( /boolean expression/ )
/statement/
As with if, LScript also allows the script programmer to use an
alternate syntax for while that is similar to AREXX:
while /boolean expression/ do
begin
...
end
There are two LScript commands that allow the script programmer to
effect the flow of looping controls: break and continue. Each
of these commands are discussed in sections found later in
this document.for
Similar to while, the for operator also provides looping
control within LScript. However, while provides limited control
of the looping construct, performing only the evaluation of
the conditional expression. The for operator differs in that
it provides for pre-loop initialization and post-loop code
execution in addition to the evaluation of the looping
condition. The C version of for takes the form:
for ( /init/ ; /expr/ ; /post/ )
/statement/
LScript also allows this simpler, AREXX-like form of the for
operator:
for /var/ = /expr/ to /expr/ [ by /expr/ ] do
begin
...
end
In either format, any variables used by the for loop operator
must have been previously declared before being used.
switch/select
LScript offers the script programmer a structured selection
mechanism, identical to its C counterpart. The switch
operator provides for the selection of code execution based
upon the numeric value of an expression:
switch ( /expression/ )
{
case /number/ :
...
break;
default:
...
break;
}
Again, LScript offers an AREXX-like version of this selection
mechanism through the use of the select operator. However,
unlike the switch operator, whose selection criteria is
limited solely to numeric values, the select control allows
whole expressions to be evaluated in determining the code to
execute:
select
when /expression/ then do
...
end
end
inline select
The inline select operator (?:) allows you to select one of
two alternatives based on a condition. This "shorthand" form
of the select operator is identical to that provided by C, and
takes the form:
/boolean expression/ ? /true select/ : /false select/
This operator can be use just about anyplace an expression can
appear in LScript. For example,
main
{
j = 1;
...
info("result is ",(j == 1 ? "yes" : "no"));
}
break
The break command, mentioned earlier, will prematurely
terminate a looping control in LScript. Should either a while or
for operator encounter a break within their domain, they will
immediately cycle to the next LScript statement following the end
of their loop control.
while(j)
{
if(j == 10)
break; // line 4
++j;
}
info("j == ", j); // line 9
In the preceding example, upon encountering the break in line
#4, LScript would cause the while loop to terminate, and would set
its internal program counter to the executable statement on
line #9 (info()).continue
continue is another command within LScript that can effect the
flow of execution of a looping operator. Whereas break caused
program execution to continue with the next LScript code line
following the loop, the continue command will cause a loop
operator to behave as though it had reached the end of its
control loop. The continue command is very similar to a goto
command with the target being the top of the control loop.
while(1)
continue; // uh oh! an infinite loop!
Next Section
Previous Section
Table of Contents
Index
Errata
© 1996 Virtual Visions, Inc.
© 1997 NewTek, Inc.